#include "init.h"
#include "comm/boot_info.h"
#include "comm/cpu_instr.h"
#include "cpu/cpu.h"
#include "cpu/irq.h"
#include "dev/timer.h"
#include "tools/log.h"
#include "tools/klib.h"
#include "tools/list.h"
#include "core/task.h"
#include "os_cfg.h"
#include "ipc/semaphore.h"
#include "core/memory.h"

void kernel_init(boot_info_t *boot_info)
{
    cpu_init();
    log_init();
    memory_init(boot_info);
    irq_init();
    timer_init();
    task_manager_init();
}

void move_to_first_task()
{
    task_t *curr = get_current_task();
    ASSERT(curr != NULL);

    tss_t *tss = &curr->tss;
    __asm__ __volatile__ (
        "jmp *%[ip]"::[ip]"r"(tss->eip)
    );
}

void init_main(void)
{
    log_printf("Kernel is running...");
    log_printf("%s\tversion: %s", "Diy-x86 os", OS_VERSION);

    first_task_init();
    move_to_first_task();
}
